/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.view;

import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import simplemetrosystem.control.ConfigureManager;
import simplemetrosystem.control.ElementManager;
import simplemetrosystem.model.charlanguage.NameMap;
import simplemetrosystem.view.bar.FloorPanel;
import simplemetrosystem.view.canvas.CanvasModel;
import simplemetrosystem.view.canvas.MetroCanvas;

/**
 *
 * @author Eric Qian
 * 
 * 软件核心类，提供作图画板，拥有元素工厂，元素管理器，元素绘制器等软件重要工具
 * 
 */
public class MetroTabbedPane extends JTabbedPane implements Observer {

    /**
     * 
     * @param frame
     * @param path
     */
    public MetroTabbedPane(MetroFrame frame, String path) {
        super();
        init(frame, path);
    }

    /**
     * 
     * @param o
     * @param arg
     */
    public void update(Observable o, Object arg) {
        //System.out.println("窗口更新");
        removeAll();
        addTabs();
    }

    /*
     * 组建初始化
     */
    private void init(MetroFrame frame, String path) {
        this.frame = frame;
        this.setTabPlacement(JTabbedPane.TOP);
        this.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        nameMap = NameMap.getInstance();
        elementManager = ElementManager.getInstance();
        //SCpanes = new ArrayList<JScrollPane>();
        //canvases = new ArrayList<MetroCanvas>();
        CanvasModel.newInstance(FloorPanel.INITIAL,
                ElementManager.getInstance().getWidth(),
                ElementManager.getInstance().getHeight());
        //新建标签栏
        addTabs();
    }

    /*
     * 初始化时生成全体地图画板，存储在第一个（0）TAB中
     */
    private void addTabs() {
        addTab(nameMap.getName("All lines"), getAllLinePane());

    //for (int i = 0; i < elementManager.getLinesSize(); i++) {
    //    addTab(elementManager.getLineAt(i).getDisplayName(), getLinePane(i));
    //}
    }

    public void setMatrixSize(int size) {
        allLineCanvas.setMatrixSize(size);
        //for (int i = 0; i < elementManager.getLinesSize(); i++) {
        //   canvases.get(i).setMatrixSize(size);
        //}
        removeAll();
        addTabs();
    }

    public JScrollPane getAllLinePane() {
        if (allLineSCPane == null) {
            allLineCanvas = new MetroCanvas(frame, -1);
            allLineSCPane = new JScrollPane(allLineCanvas,
                    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
            allLineSCPane.setWheelScrollingEnabled(true);
        }
        return allLineSCPane;
    }

    /*
    public JScrollPane getLinePane(int i) {
    if (i == SCpanes.size()) {
    MetroCanvas aCanvas = new MetroCanvas(frame, i);
    canvases.add(aCanvas);
    JScrollPane lineSCPane = new JScrollPane(aCanvas,
    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    lineSCPane.setWheelScrollingEnabled(true);
    SCpanes.add(lineSCPane);
    }
    return SCpanes.get(i);
     * }
     */
    /**
     * 
     * @return
     */
    public MetroCanvas getAllLineCanvas() {
        return allLineCanvas;
    }
    /**
    public MetroCanvas getLineCanvas(int i) {
    if (i < canvases.size()) {
    return canvases.get(i);
    }
    return null;
    }*/
    private MetroFrame frame;
    private NameMap nameMap;
    private ElementManager elementManager;
    private JScrollPane allLineSCPane;
    private MetroCanvas allLineCanvas;
}

